//
//  AppTools.m
//  UI豆瓣2
//
//  Created by dllo on 15/11/6.
//  Copyright © 2015年 蓝鸥科技. All rights reserved.
//

#import "AppTools.h"
#import "AFNetworking.h"
@implementation AppTools

+ (void)getDataWithPath:(NSString *)path block:(AppToolsBlock)block{
    
    //编码
    NSString *urlEncode = [path stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]];
    
    AFHTTPRequestOperationManager* manager = [AFHTTPRequestOperationManager manager];
    manager.responseSerializer.acceptableContentTypes = [NSSet setWithObjects:@"text/plain",@"text/json",@"application/json",@"text/javascript",@"text/html",nil];
    [manager GET:urlEncode parameters:nil success:^(AFHTTPRequestOperation *operation, id responseObject) {
       
        block(responseObject);
        
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        
        NSLog(@"失败==== %@",error);
        
    }];
    
}


+ (void)getImageWithURL:(NSString *)url block:(HeadImgBlock)block{
    NSString *urlStr = url;
    NSString *strEncode = [urlStr stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]];
    NSURL *urll = [NSURL URLWithString:strEncode];
    NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:urll];
    NSURLSession *session = [NSURLSession sharedSession];
    NSURLSessionDataTask *task = [session dataTaskWithRequest:request completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {
        block(data);
    }];
    [task resume];
}


@end
